<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=s, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1 class="time"></h1>
    <button class="off">暂停</button>
    <button class="on">继续</button>
    <script>
        var time = document.querySelector(".time");
        var off = document.querySelector(".off");
        var on = document.querySelector(".on");
        var nowTime = '';
        var t1 = setInterval(() => {
            resetTime(new Date());
        }, 1000);
        function resetTime(now){
            nowTime = now;
            var hours = now.getHours();
            hours = hours>=10?hours:"0"+hours;
            var min = now.getMinutes();
            min = min>=10?min:"0"+min;
            var sec = now.getSeconds();
            sec = sec>=10?sec:"0"+sec;
            time.textContent = `${hours}:${min}:${sec}`;
        }
        off.onclick = function(){
            clearInterval(t1);
        }
        on.onclick = function(){
            t1 = setInterval(()=>{
                resetTime(new Date());
            },1000);
        }
    </script>
</body>
</html>